package com.jack.thinking.java._22.swing.pane;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import com.utils.SwingConsole;

/**
 * 弹出层，弹出Frame
 * @author wangbingwu
 *
 */
public class MyDialog extends JDialog{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public MyDialog(JFrame parent) {
		super(parent, "My dialog", true);
		setLayout(new FlowLayout());
		add(new JLabel("Here is my dialog"));
		JButton ok = new JButton("OK");
		ok.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				dispose(); // close this dialog
			}
		});
		
		add(ok);
		setSize(150, 125);
	}
	
	public static void main(String[] args) {
		SwingConsole.run(new Dialogs(), 125, 75);
	}
}

class Dialogs extends JFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JButton b1 = new JButton("Dialog Box");
	private MyDialog dlg = new MyDialog(null);
	
	public Dialogs() {
		b1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				dlg.setVisible(true);
			}
		});
		add(b1);
	}
}
